home *** CD-ROM | disk | FTP | other *** search
- Imports System.Data
- Imports System.Data.OleDb
-
- Public Class MasterDetailGridsForm
- Inherits System.Windows.Forms.Form
-
- #Region " Windows Form Designer generated code "
-
- Public Sub New()
- MyBase.New()
-
- 'This call is required by the Windows Form Designer.
- InitializeComponent()
-
- 'Add any initialization after the InitializeComponent() call
-
- End Sub
-
- 'Form overrides dispose to clean up the component list.
- Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
- If disposing Then
- If Not (components Is Nothing) Then
- components.Dispose()
- End If
- End If
- MyBase.Dispose(disposing)
- End Sub
- Friend WithEvents grdPublishers As System.Windows.Forms.DataGrid
- Friend WithEvents grdTitles As System.Windows.Forms.DataGrid
-
- 'Required by the Windows Form Designer
- Private components As System.ComponentModel.Container
-
- 'NOTE: The following procedure is required by the Windows Form Designer
- 'It can be modified using the Windows Form Designer.
- 'Do not modify it using the code editor.
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.grdPublishers = New System.Windows.Forms.DataGrid()
- Me.grdTitles = New System.Windows.Forms.DataGrid()
- CType(Me.grdPublishers, System.ComponentModel.ISupportInitialize).BeginInit()
- CType(Me.grdTitles, System.ComponentModel.ISupportInitialize).BeginInit()
- Me.SuspendLayout()
- '
- 'grdPublishers
- '
- Me.grdPublishers.AllowNavigation = False
- Me.grdPublishers.AlternatingBackColor = System.Drawing.Color.LightGray
- Me.grdPublishers.BackColor = System.Drawing.Color.Gainsboro
- Me.grdPublishers.BackgroundColor = System.Drawing.Color.Silver
- Me.grdPublishers.BorderStyle = System.Windows.Forms.BorderStyle.None
- Me.grdPublishers.CaptionBackColor = System.Drawing.Color.LightSteelBlue
- Me.grdPublishers.CaptionForeColor = System.Drawing.Color.MidnightBlue
- Me.grdPublishers.CaptionText = "Publishers"
- Me.grdPublishers.DataMember = ""
- Me.grdPublishers.FlatMode = True
- Me.grdPublishers.Font = New System.Drawing.Font("Tahoma", 8!)
- Me.grdPublishers.ForeColor = System.Drawing.Color.Black
- Me.grdPublishers.GridLineColor = System.Drawing.Color.DimGray
- Me.grdPublishers.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
- Me.grdPublishers.HeaderBackColor = System.Drawing.Color.MidnightBlue
- Me.grdPublishers.HeaderFont = New System.Drawing.Font("Tahoma", 8!, System.Drawing.FontStyle.Bold)
- Me.grdPublishers.HeaderForeColor = System.Drawing.Color.White
- Me.grdPublishers.LinkColor = System.Drawing.Color.MidnightBlue
- Me.grdPublishers.Location = New System.Drawing.Point(16, 16)
- Me.grdPublishers.Name = "grdPublishers"
- Me.grdPublishers.ParentRowsBackColor = System.Drawing.Color.DarkGray
- Me.grdPublishers.ParentRowsForeColor = System.Drawing.Color.Black
- Me.grdPublishers.SelectionBackColor = System.Drawing.Color.CadetBlue
- Me.grdPublishers.SelectionForeColor = System.Drawing.Color.White
- Me.grdPublishers.Size = New System.Drawing.Size(560, 136)
- Me.grdPublishers.TabIndex = 0
- '
- 'grdTitles
- '
- Me.grdTitles.AlternatingBackColor = System.Drawing.Color.Lavender
- Me.grdTitles.BackColor = System.Drawing.Color.WhiteSmoke
- Me.grdTitles.BackgroundColor = System.Drawing.Color.LightGray
- Me.grdTitles.BorderStyle = System.Windows.Forms.BorderStyle.None
- Me.grdTitles.CaptionBackColor = System.Drawing.Color.LightSteelBlue
- Me.grdTitles.CaptionForeColor = System.Drawing.Color.MidnightBlue
- Me.grdTitles.CaptionText = "Titles"
- Me.grdTitles.DataMember = ""
- Me.grdTitles.FlatMode = True
- Me.grdTitles.Font = New System.Drawing.Font("Tahoma", 8!)
- Me.grdTitles.ForeColor = System.Drawing.Color.MidnightBlue
- Me.grdTitles.GridLineColor = System.Drawing.Color.Gainsboro
- Me.grdTitles.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
- Me.grdTitles.HeaderBackColor = System.Drawing.Color.MidnightBlue
- Me.grdTitles.HeaderFont = New System.Drawing.Font("Tahoma", 8!, System.Drawing.FontStyle.Bold)
- Me.grdTitles.HeaderForeColor = System.Drawing.Color.WhiteSmoke
- Me.grdTitles.LinkColor = System.Drawing.Color.Teal
- Me.grdTitles.Location = New System.Drawing.Point(16, 168)
- Me.grdTitles.Name = "grdTitles"
- Me.grdTitles.ParentRowsBackColor = System.Drawing.Color.Gainsboro
- Me.grdTitles.ParentRowsForeColor = System.Drawing.Color.MidnightBlue
- Me.grdTitles.SelectionBackColor = System.Drawing.Color.CadetBlue
- Me.grdTitles.SelectionForeColor = System.Drawing.Color.WhiteSmoke
- Me.grdTitles.Size = New System.Drawing.Size(560, 136)
- Me.grdTitles.TabIndex = 0
- '
- 'MasterDetailGridsForm
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- Me.ClientSize = New System.Drawing.Size(592, 317)
- Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.grdTitles, Me.grdPublishers})
- Me.Name = "MasterDetailGridsForm"
- Me.Text = "MasterDetailGridsForm"
- CType(Me.grdPublishers, System.ComponentModel.ISupportInitialize).EndInit()
- CType(Me.grdTitles, System.ComponentModel.ISupportInitialize).EndInit()
- Me.ResumeLayout(False)
-
- End Sub
-
- #End Region
-
- Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- CreateDataSet()
- InitializeBinding()
- End Sub
-
- Dim dsBiblio As New DataSet()
-
- Sub CreateDataSet()
- ' Open a connection to the Biblio.mdb database.
- Dim cn As New OleDbConnection(BiblioConnString)
- cn.Open()
-
- ' Create a data adapter for the Publisher table.
- Dim daPublishers As New OleDbDataAdapter("SELECT * FROM Publishers", cn)
- ' Fill the DataSet object with Publishers data.
- daPublishers.Fill(dsBiblio, "Publishers")
-
- ' Create a data adapter for the Titles table.
- Dim daTitles As New OleDbDataAdapter("SELECT * FROM Titles", cn)
- ' Fill the DataSet object with Titles data.
- daTitles.Fill(dsBiblio, "Titles")
-
- ' Create a Relation between the two table
- dsBiblio.Relations.Add("PubTitles", dsBiblio.Tables("Publishers").Columns("PubID"), dsBiblio.Tables("Titles").Columns("PubId"))
-
- ' Close the connection
- cn.Close()
- End Sub
-
- Sub InitializeBinding()
- ' Bind the master grid to the Publishers table.
- grdPublishers.DataSource = dsBiblio
- grdPublishers.DataMember = "Publishers"
- ' Bind the detail grid to the Titles table.
- grdTitles.DataSource = dsBiblio
- grdTitles.DataMember = "Publishers.PubTitles"
- End Sub
-
- End Class
-